package com.unknowpupil.alibaba.cloud.oauth.configure;



import com.unknowpupil.alibaba.cloud.oauth.vo.SysUserAuthentication;
import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken;
import org.springframework.security.oauth2.common.OAuth2AccessToken;
import org.springframework.security.oauth2.provider.OAuth2Authentication;
import org.springframework.security.oauth2.provider.token.TokenEnhancer;

import java.util.HashMap;
import java.util.Map;
/**
 * @Description: <p>
 *
 * </p>
 * @Author: <a> w10g </a>
 * @CreateDate: Create in 2020/5/19 19:12
 * @Classname: CustomTokenEnhancer
 * @Version: 1.0
 */

/**
 *
 * token生成携带的信息
 *
 */
public class CustomTokenEnhancer implements TokenEnhancer {

    @Override
    public OAuth2AccessToken enhance(OAuth2AccessToken accessToken, OAuth2Authentication authentication) {
        final Map<String, Object> additionalInfo = new HashMap<>();
        SysUserAuthentication user = (SysUserAuthentication) authentication.getUserAuthentication().getPrincipal();
        additionalInfo.put("user_id", user.getId());
        additionalInfo.put("user_phone", user.getPhone());
        ((DefaultOAuth2AccessToken) accessToken).setAdditionalInformation(additionalInfo);
        return accessToken;
    }

}
